<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <div id="test">
    <h2 :style="{opacity}">Vue So Easy!</h2>
    <button @click="$destroy()">销毁vm</button>
  </div>

  <script src="../js/vue.js"></script>
  <script>
    new Vue({
      el: "#test",
      data: {
        opacity:1
      },
      mounted(){
        this.intervalId = setInterval(()=>{
            console.log('----');
            this.opacity -= 0.1
            if(this.opacity<=0){
                this.opacity = 1
            } 
        },100)
      },
      beforeDestroy(){
        clearInterval(this.intervalId)
      }
    })
  </script>
</body>
</html>